import {
  DashboardOutlined,
  HomeOutlined,
  ProjectOutlined,
  SettingOutlined,
} from "@vicons/antd";
import { NIcon } from "naive-ui";
import { h } from "vue";
import {
  createRouter,
  createWebHistory,
  type RouteRecordRaw,
} from "vue-router";

export const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "root",
    redirect: "/home",
    component: () => import("components/layout/PLayout.vue"),
    meta: {
      icon: () => h(NIcon, null, { default: () => h(HomeOutlined) }),
      sort: 1,
    },
    children: [
      {
        path: "/home",
        name: "home",
        meta: {
          title: "首页",
          affix: true,
          icon: () => h(NIcon, null, { default: () => h(HomeOutlined) }),
          sort: 2,
        },
        component: () => import("@/views/PlusTableDemo.vue"),
      },
    ],
  },
  {
    path: "/dashboard",
    name: "dashboard",
    redirect: "/dashboard/console",
    component: () => import("components/layout/PLayout.vue"),
    meta: {
      title: "Dashboard",
      icon: () => h(NIcon, null, { default: () => h(DashboardOutlined) }),
      permissions: [
        "dashboard_console",
        "dashboard_console",
        "dashboard_workplace",
      ],
      sort: 3,
    },
    children: [
      {
        path: "console",
        name: "dashboard_console",
        meta: {
          title: "主控台",
          permissions: ["dashboard_console"],
          sort: 4,
        },
        component: () => import("@/views/PModalDemo.vue"),
      },
      {
        path: "workplace",
        name: "dashboard_workplace",
        meta: {
          title: "工作台",
          keepAlive: true,
          permissions: ["dashboard_workplace"],
          sort: 5,
        },
        component: () => import("@/views/PlusTableDemo.vue"),
      },
    ],
  },
  {
    path: "/setting",
    name: "Setting",
    redirect: "/setting/account",
    component: () => import("components/layout/PLayout.vue"),
    meta: {
      title: "设置页面",
      icon: () => h(NIcon, null, { default: () => h(SettingOutlined) }),
      sort: 6,
    },
    children: [
      {
        path: "account",
        name: "setting-account",
        meta: {
          title: "个人设置",
          sort: 7,
        },
        component: () => import("@/views/PlusTableDemo.vue"),
      },
      {
        path: "system",
        name: "setting-system",
        meta: {
          title: "系统设置",
          sort: 8,
        },
        component: () => import("@/views/PlusTableDemo.vue"),
      },
    ],
  },
  {
    path: "/about",
    name: "about",
    component: () => import("components/layout/PLayout.vue"),
    meta: {
      sort: 9,
      isRoot: true,
      activeMenu: "about_index",
      icon: () => h(NIcon, null, { default: () => h(ProjectOutlined) }),
    },
    children: [
      {
        path: "index",
        name: `about_index`,
        meta: {
          title: "关于项目",
          activeMenu: "about_index",
          sort: 10,
        },
        component: () => import("@/views/PlusTableDemo.vue"),
      },
    ],
  },
  {
    path: "/:path(.*)*",
    name: "ErrorPage",
    component: () => import("components/layout/PLayout.vue"),
    meta: {
      title: "ErrorPage",
      hideBreadcrumb: true,
    },
    children: [
      {
        path: "/:path(.*)*",
        name: "ErrorPageSon",
        component: () => import("@/views/PlusTableDemo.vue"),
        meta: {
          title: "ErrorPage",
          hideBreadcrumb: true,
        },
      },
    ],
  },
  {
    path: "/redirect",
    name: "Redirect",
    redirect: "/",
    meta: {
      title: "Redirect",
      hideBreadcrumb: true,
    },
    children: [
      {
        path: "/redirect/:path(.*)",
        name: `RedirectSon`,
        component: () => import("@/views/PlusTableDemo.vue"),
        meta: {
          title: "Redirect",
          hideBreadcrumb: true,
        },
      },
    ],
  },
  {
    path: "/oidc-callback",
    name: "oidc-callback",
    component: () => import("@/views/PlusTableDemo.vue"),
    meta: {
      ignoreAuth: true,
      title: "OIDC回调处理",
    },
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes: routes,
  strict: true,
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

export default router;
